home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / POKER.TST / PLANPOKR.C < prev    next >
C/C++ Source or Header  |  1995-11-12  |  3KB  |  109 lines

  1. /* ============ */
  2. /* planpokr.c    */
  3. /* ============ */
  4. #include <defcodes.h>
  5. #include <miscdefs.h>
  6. #include "pokrprob.c"
  7.  
  8. #define    DEFAULT_CELL_COUNT     5
  9. #define    DEFAULT_DATA_WIDTH    10
  10. #define    DEFAULT_HAND_SIZE     5
  11.  
  12. #define    HI_POW    15
  13. #define    LO_POW     4
  14. #define    ACT(X)    #X
  15. #define    NEED_POW(L,U)    \
  16.     "Enter power of 2 for largest integer [>= " ACT(L) ", <= " ACT(U) "]: "
  17. /* ==================================================================== */
  18. /* PlanPoker - Main program to plan a poker-test run            */
  19. /* ==================================================================== */
  20. void
  21. main()
  22. {
  23.     /* ------------------------------------------------ */
  24.     /* This program will request the following data:    */
  25.     /*                                                  */
  26.     /*    1. Number of cards per hand to be examined.     */
  27.     /*    2. Data Width of numbers to be generated.       */
  28.     /*     In this application, data width is a         */
  29.     /*       number that represents the length of         */
  30.     /*     the random-number cycle.  Suggested          */
  31.     /*       values:                                      */
  32.     /*                                                  */
  33.     /*        5, 10, 16, 32                           */
  34.     /*                                                  */
  35.     /*       For my own part, I have clamped the entry    */
  36.     /*       to the limits (5, 128).                      */
  37.     /*                                                  */
  38.     /*    2. Minimum Cell Expectation in Each Category    */
  39.     /*                                                  */
  40.     /*       This is typically 5 or 10, preferably 10,    */
  41.     /*       but certainly no less than 5 or you'll git    */
  42.     /*       et by the hogs.
  43.     /* ------------------------------------------------ */
  44.  
  45.     AbortGracefully();            /* Causes ^C to Behave */
  46.  
  47.     while (main)
  48.     {
  49.     int    HandSize = 0;
  50.     int    CellExpect = 0, i, DataWidth = 0;
  51.     double    PokerProbVals[64], ProbTotal;
  52.  
  53.     GetInt("Enter Number of Cards Per Hand: ", &HandSize);
  54.     GetInt("Enter Data Width (e.g. 10, 16, 32, ...): ", &DataWidth);
  55.  
  56.     GetInt("Enter Minimum Cell Expectation in Each Category: ",
  57.         &CellExpect);
  58.  
  59.     if (HandSize > 0)
  60.     {
  61.         printf("HandSize = %d\n", HandSize);
  62.     }
  63.     else
  64.     {
  65.         HandSize = DEFAULT_HAND_SIZE;
  66.         printf("HandSize is set to %d by default\n", HandSize);
  67.     }
  68.     if (DataWidth < HandSize)
  69.     {
  70.         DataWidth = HandSize;
  71.         printf("DataWidth Must Be >= HandSize ... Setting ");
  72.     }
  73.     if (DataWidth > 0)
  74.     {
  75.         printf("DataWidth = %d\n", DataWidth);
  76.     }
  77.     else
  78.     {
  79.         DataWidth = DEFAULT_DATA_WIDTH;
  80.         printf("DataWidth is set to %d by default\n", DataWidth);
  81.     }
  82.     if (CellExpect > 0)
  83.     {
  84.         printf("Minimum Cell Expectation = %d\n", CellExpect);
  85.     }
  86.     else
  87.     {
  88.         CellExpect = DEFAULT_CELL_COUNT;
  89.         printf("Minimum Cell Expectation is set to %d by default\n",
  90.         CellExpect);
  91.     }
  92.  
  93.     CalcPokerProbs(HandSize, DataWidth, PokerProbVals);
  94.     printf("\nPoker Probabilities:\n  r      Pr%15s", "");
  95.     printf("Cell Expectation     # Variates Required\n");
  96.     ProbTotal = 0;
  97.     for (i = HandSize; i >= 1; --i)
  98.     {
  99.         double  DevReqd = floor(0.5 + CellExpect/PokerProbVals[i - 1]);
  100.  
  101.         ProbTotal += PokerProbVals[i - 1];
  102.  
  103.         printf("%3d  %.11e%10s", i, PokerProbVals[i - 1], "");
  104.         printf("%2d%15s%.f\n", CellExpect, "", DevReqd);
  105.     }
  106.     printf("     %.11e  (Total)\n", ProbTotal);
  107.     }
  108. }
  109.